import type { PropsWithChildren } from 'react';
import { type DialogProps, Dialog, Button } from 'react-native-paper';
interface DefineProps extends DialogProps {
  visible: boolean;
  setVisible: (visible: boolean) => void;
  onSubmit: () => void;
  width?: `${number}%` | number;
  title: string;
}
export default (props: DefineProps & PropsWithChildren) => {
  const { visible, setVisible, onSubmit, title, width = '30%', ...rest } = props;
  return (
    <Dialog
      {...rest}
      style={{
        backgroundColor: '#fff',
        width,
        alignSelf: 'center',
      }}
      visible={visible}
      onDismiss={() => setVisible(false)}>
      <Dialog.Icon icon="alert" />
      <Dialog.Title
        style={{
          textAlign: 'center',
        }}>
        {title}
      </Dialog.Title>
      <Dialog.Content>{props.children}</Dialog.Content>
      <Dialog.Actions>
        <Button textColor="#0A59F7" onPress={() => setVisible(false)}>
          取消
        </Button>
        <Button textColor="#0A59F7" onPress={() => onSubmit()}>
          确定
        </Button>
      </Dialog.Actions>
    </Dialog>
  );
};
